'''
Created on 30/03/2009

@author: eh01
'''

from xml.etree import ElementTree
from yarra import helper
from yarra.datastore import dsconstants
from yarra.datastore.dso import DSO
from yarra.datastore.dst import DST
from yarra.handler.speara2ahandler import SPEARA2AHandler
import unittest


class Test(unittest.TestCase):


    def setUp(self):
        pass


    def tearDown(self):
        pass


    def test_spear_a2a_handler_case1(self):
        # create web service name dst
        web_service_name_dst = DST(subject=dsconstants.SUBJECT_ROOT,
            predicate=dsconstants.PREDICATE_SPEAR_A2A_WEB_SERVICE_NAME,
            literal='LxSpearEcho')
        
        # create soap message
        access_token = helper.get_access_token()
        env = ElementTree.Element('{http://schemas.xmlsoap.org/soap/envelope/}Envelope')
        body = ElementTree.SubElement(env, '{http://schemas.xmlsoap.org/soap/envelope/}Body')
        echo = ElementTree.SubElement(body, '{http://test.webservice.spear.lx.dse.vic.gov.au}echo')
        echo.append(access_token)
        input = ElementTree.SubElement(echo,
            '{http://test.webservice.spear.lx.dse.vic.gov.au}input')
        input.text = "Hello Ed"
        soap = '<?xml version="1.0" encoding="utf-8" ?>\r\n' + ElementTree.tostring(env)
        
        soap_message_dst = DST(subject=dsconstants.SUBJECT_ROOT,
            predicate=dsconstants.PREDICATE_SOAP_MESSAGE,
            literal=soap)        
        
        dso = DSO([])
        dso.add_dst(soap_message_dst)
        dso.add_dst(web_service_name_dst)
        
        spear_a2a_handler = SPEARA2AHandler()
        spear_a2a_handler.do(dso)

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.test_spear_a2a_handler_case1']
    unittest.main()